package day_13;

import java.util.Scanner;
import java.util.Stack;

/////////此题未解决
public class ques2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (scan.hasNextInt()) { // 注意 while 处理多个 case
        int N=scan.nextInt();
        int M=scan.nextInt();

        Stack<Integer> stack=new Stack<>();
        int count=0;
        int moveTips=0;
        while(N!=M){
            moveTips=move(stack,N,M);
            stack=new Stack<>();
            if(moveTips==0){
                System.out.println(-1);
                return;
            }
            N+=moveTips;
            count++;
            if(N>M){
                System.out.println(-1);
            }
        }
        System.out.println(count);
    }

    // }

    public static int move(Stack<Integer> stack, int n, int m){
        for(int i=2;i<n;i++){
            if(n%i==0){
                stack.push(i);
            }
        }
        //栈中储存了该N的中的公约数(栈顶向下逐渐变小)
        while(!stack.isEmpty()){
            if(n+stack.peek()<=m){
                return stack.peek();
            }else{
                stack.pop();
            }
        }
        return 0;
    }

}



